using System.Collections;
using System.Collections.Generic;
using EventUtils;
using UnityEngine;
using UnityEngine.UI;

namespace View.Instant
{
    
    public class GameEndView : View
    {
        private Text mtxtTitle;
        private Button mbtnBack;
        private Button mbtnAgain;
        public override void OnLoad()
        {
            base.OnLoad();

            mbtnBack = transform.Find("btnBack").GetComponent<Button>();
            mbtnAgain = transform.Find("btnretry").GetComponent<Button>();
            mtxtTitle = transform.Find("title").GetComponent<Text>();
            
            AddClickListener(mbtnBack,() =>
            {
                MJCtrl.Instance().OnDesctroyCard();
                UIManager.Instance.Close(ViewName.GameEndView);
                UIManager.Instance.Close(ViewName.Game1View);
                UIManager.Instance.Close(ViewName.Game2View);
                UIManager.Instance.Show(ViewName.LobbyView);
            });
            
            AddClickListener(mbtnAgain, () =>
            {
                UIManager.Instance.Close(ViewName.GameEndView);

                GameLocalInfo.OnUpdatePlayerPower(-1);
                // GameHelp.GameLevel = 1;
                EventCenter.BroadCast(EventUtils.EventType.EVENT_GAME_START);
            });
        }

        public override void OnShow(params object[] args)
        {
            base.OnShow();
            mtxtTitle.text = "Lose";
            if (args.Length >= 1)
            {
                int win = (int)args[0];
                if (win == 1)
                {
                    mtxtTitle.text = "Win";
                }
            }
        }

        public override void OnClose(params object[] args)
        {
            base.OnClose();
        }
    }
}
